Programming Languages Section

Objective-C

Card image
Post by Amina Delali, September 18th,2021

Some Facts

Objective-C is a general purpose oriented programming language that combines SmallTalk messaging Style and C programming language.

It is principally used to develop software for OS X and iOS systems.  It doesn’t support multiple inheritance but it offers dynamic runtime and exceptions handling. It is good for networking and game development. And it is compatible with C and C++ codes and libraries



How to install it

  • on Windows:

    You will have to install 2 principal components :

    1. the MinGW development environment: before anything else, you will need to install MinGW following the instructions available in this page
    2. the GNUstep Core: you will first need to install the gnustep-msys-system package that contains all the necessary packages  to run GNUstep. Then install the GNUstep Core ( GNUstep libraries ). You may also want to download and install the gnustep-devel package in order to develop your own GNUstep applications. All these installations can be simply done by downloading and running the windows installers available in the following download page.
    3. to run an Objective-C code you will have to run the Shell program from: Start -> All Programs -> GNUstep -> Shell. Then from the folder containing your code’s file run the gcc command using the following option 'gnustep-config --objc-flags' . For more details of how to run your code on windows check this page.
  • on ubuntu :

    Just open the terminal and run the following commands:

    sudo apt update
    sudo apt –y install gobjc gnustep gnustep-devel

  • To test your installation, you will have to test the compilation of a code written in Objective-C. To do so, you can just follow the steps described in the next section.

In the video below, the details of the installation of the Objective-Clanguage on Ubuntu.

The Hello World Example

To write, compile, and run the Hello World Code in Objective-C on Ubuntu, just follow these steps:

  1. Create a new file in the Home folder and name it “Hello.m” 
  2. Write the following code in your file:
  3. #import <Foundation/Foundation.h>

    int main (int argcconst char argv[])
    {
      NSAutoreleasePool *pool = [[NSAutoreleasePool allocinit ];
      NSLog (@"Hello World!");
      [pool drain];
      return 0;
    }
  4. After saving your file, open the terminal (from the Home folder) and run the following command to compile your code: gcc $(gnustep-config --objc-flags) -o hello hello.m $(gnustep-config --base-libs)
  5. To run the generated executable, run the following command: ./hello


Additional Information

For more information about the Objective-C language and the corresponding code, you can check the following pages:

Something to say ?

If you want to add something about the Objective-C language or about this post, please feel free to do it by commenting below 🙂 .